/*
 * Magnoteter.h
 *
 *  Created on: Jan 18, 2014
 *      Author: ppks
 */

#ifndef MAGNETOMETER_H_
#define MAGNETOMETER_H_

/******************************************************************************/
/* Magnetometer Configuration                                                 */
/******************************************************************************/
#define MAG_UPDATE_PERIOD           100000
#define MAG_CALIBRATION_TIME        30000000

#if (MAGNETOMETER_TYPE == HMC5883)
/* Define the I2C address if not defined yet in global config.h */
#ifndef MAG_ADDRESS
    #define MAG_ADDRESS             0x1E
#endif /* #ifndef MAG_ADDRESS */

/* Define the data register */
#define MAG_DATA_REGISTER           0x03

/* Define other configuration */
#define HMC58X3_R_CONFA             0
#define HMC58X3_R_CONFB             1
#define HMC58X3_R_MODE              2
#define HMC58X3_X_SELF_TEST_GAUSS   (+1.16)   /* X axis level when bias current is applied. */
#define HMC58X3_Y_SELF_TEST_GAUSS   (+1.16)   /* Y axis level when bias current is applied. */
#define HMC58X3_Z_SELF_TEST_GAUSS   (+1.08)   /* Y axis level when bias current is applied. */
#define SELF_TEST_LOW_LIMIT         (243.0/390.0)  /* Low limit when gain is 5. */
#define SELF_TEST_HIGH_LIMIT        (575.0/390.0)  /* High limit when gain is 5. */
#define HMC_POS_BIAS                1
#define HMC_NEG_BIAS                2
#endif /* (MAGNETOMETER_TYPE == HMC5883) */

/********************************************************************************/
/* Exported Variables Declaration                                               */
/********************************************************************************/

/********************************************************************************/
/* Exported Functions Prototypes                                                */
/********************************************************************************/
extern void Magnetometer_Init(void);
extern void Magnetometer_ReadRawADC(void);
extern uint8_t Magnetometer_GetNewData(void);

#endif /* MAGNETOMETER_H_ */
